// ---------- localStorage ----------
export function setLocal(key: string, value: string) {
  window.localStorage.setItem(key, value);
}

export function getLocal(key: string): string | null {
  return window.localStorage.getItem(key);
}

export function removeLocal(key: string) {
  window.localStorage.removeItem(key);
}

// ---------- sessionStorage ----------
export function setSession(key: string, value: string) {
  window.sessionStorage.setItem(key, value);
}

export function getSession(key: string): string | null {
  return window.sessionStorage.getItem(key);
}

export function removeSession(key: string) {
  window.sessionStorage.removeItem(key);
}

// ---------- Cookie ----------
export function setCookie(name: string, value: string, days = 7, path = "/") {
  const expires = new Date(Date.now() + days * 864e5).toUTCString();
  document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; expires=${expires}; path=${path}`;
}

export function getCookie(name: string): string | null {
  const match = document.cookie.match(
    new RegExp("(^| )" + encodeURIComponent(name) + "=([^;]+)")
  );
  return match ? decodeURIComponent(match[2]) : null;
}

export function removeCookie(name: string, path = "/") {
  document.cookie = `${encodeURIComponent(name)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=${path}`;
} 